<template>
	<!-- 新闻显示模块 -->
	<view class="newsbox">
		<!-- 图片 -->
		<view class="pic">
			<image :src="item.picurl" mode="aspectFill"></image>
		</view>
		<!-- 文字 -->
		<view class="text">
			<!-- 新闻标题 -->
			<view class="title">
				{{item.title}}
			</view>
			<!-- 作者 -->
			<view class="info" v-if="!item.looktime">
				<text>{{item.author}}</text>
				<text>{{item.hits}}浏览</text>
			</view>
			<view class="info" v-else>
				浏览时间：{{item.looktime}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "newsbox",
		// 页面传递过来的数据
		props: {
			item: {
				type: Object,
				default () {
					return {
						title: "组件默认标题",
						author: "张三",
						hits: 668,
						picurl: "../../static/images/OIP-C.jpg",
						// lookTime: "2023-5-16 15:00:00"

					}
				}
			}
		},
		data() {
			return {

			};
		}
	}
</script>

<style lang="scss">
	.newsbox {
		display: flex;

		.pic {
			width: 230rpx;
			height: 160rpx;

			image {
				width: 100%;
				height: 100%;

			}
		}

		.text {
			flex: 1;
			padding: 10rpx 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				font-size: 36rpx;
				color: #333;
				// 超过两行文本就隐藏为省略号
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 2;
				line-clamp: 2;
				-webkit-box-orient: vertical;
			}

			.info {
				font-size: 26rpx;
				color: #999;

				text {
					padding-right: 30rpx;
				}
			}
		}
	}
</style>